/**
 * 比较样式
 * @param {*} n 新style
 * @param {*} o 旧style
 * @returns
 */
export function compareStyle(n, o) {
  const n_paint = n.paint || {}
  const o_paint = o.paint || {}

  for (let i in n_paint) {
    if (n_paint[i] !== o_paint[i]) {
      return ['paint', i, n_paint[i]]
    }
  }

  const n_layout = n.layout || {}
  const o_layout = o.layout || {}

  for (let i in n_layout) {
    if (n_layout[i] !== o_layout[i]) {
      return ['layout', i, n_layout[i]]
    }
  }
}

export function setPaintProperty(map, layerid, property, val) {
  map.setPaintProperty(layerid, property, val)
}

export function setLayoutProperty(map, layerid, property, val) {
  map.setLayoutProperty(layerid, property, val)
}

export function presetIcon(map, name, iconUrl) {
  if (!map.hasImage(name)) {
    map.loadImage(iconUrl, (error, image) => {
      if (error) throw error
      map.addImage(name, image)
    })
  }
}

export function moveLayer(map, id, beforeLayerId) {
  map.moveLayer(id, beforeLayerId)
}
